<?php

namespace App\Service;

use App\Constants\ErrorCode;
use App\Library\Common;
use App\Model\DistributionCenterTag;
use App\Model\LinkFile;
use App\Model\LinkIndustry;
use App\Model\Landmark;
use App\Model\Product;
use App\Model\ProductSpecKey;
use App\Model\ProductSpecValue;
use App\Model\Sku;
use App\Model\SkuAudit;
use App\Model\SkuPrice;
use Hyperf\DbConnection\Db;
use Hyperf\Snowflake\IdGeneratorInterface;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerInterface;
use Hyperf\Di\Annotation\Inject;
use function Symfony\Component\Translation\t;

class SkuAuditService extends BaseService
{

    /**
     * @param array $sku_list
     * @param int $product_id
     * @param int $audit_id
     * @return bool
     */

    //    关联数据插入
    public function sku_audit_insert(array  $sku_list,int $product_id,int $audit_id)
    {
        $audit_arr = [];
        foreach ($sku_list as $key=>$value){
            $value['spec_value'] = json_encode($value['spec_value']);
            $value['step_price'] = json_encode($value['step_price']);
            $value['audit_id'] = $audit_id;
            $audit_arr[] = $value;
        }
        if($audit_arr){
            SkuAudit::query()->insert($audit_arr);
        }
        return true;
    }

    //    关联数据插入
    public function sku_audit_insert_with_search(array  $sku_list,int $product_id,int $audit_id)
    {
        $audit_arr = [];
        foreach ($sku_list as $key=>$value){
            unset($value['file_info']);
            $value['spec_value'] = json_encode($value['spec_value']);
            $value['step_price'] = json_encode($value['step_price']);
            $value['audit_id'] = $audit_id;
            $audit_arr[] = $value;
        }
        if($audit_arr){
            SkuAudit::query()->insert($audit_arr);
        }
        return true;
    }
}